#include <iostream>

int MaxSodaNum(int n)
{
    int soda = 0;
    int bottle = n;
    while(bottle >= 3){
        //换气水,能直接换temp瓶
        int temp = bottle / 3;
        soda += temp;  
        bottle = (bottle % 3);  //换完后的瓶子数
        bottle += temp;  // 换来的汽水喝完的瓶子+原来剩的瓶子数
    }
    if(bottle+1 == 3)
        ++soda;
    
    return soda;
}

int main()
{
    int n;
    while(std::cin >> n){
        if(n == 0)
            break;
        std::cout << MaxSodaNum(n) << std::endl;
    }
    return 0;
}